<?php
	
	// constantes de la aplicacion
	define('URL_SITIO', 'http://www.bienesstaronline.com');
	
	/*
	$bodyEmail = '<table>solo probando';

	$datosEmail->body = $bodyEmail;
	$datosEmail->emails[0] = 'jairors1966@gmail.com';
	$datosEmail->asuntoEmail = 'Nuevo carrito de compras';

	//$dataEmail->email_from = EMAIL_FROM;
	//$dataEmail->emailMU_fromName = SITE_NAME;
	$resultado = enviarEmail($datosEmail);
	
	var_dump($resultado);
	*/

	/**
	*	Funcion encargada de enviar los emails en la aplicación.
	*/
	function enviarEmail($data){
		include_once("phpmailer/class.phpmailer.php");
		$mail = new PHPMailer();
		$mail->IsHTML(true);
		
		$mail->Body = $data->body;
		
		foreach ($data->emails as $address) {
			$mail->AddAddress($address);
		}
		
		for ($i=0; $i < count($data->email_attachment); $i++) {
			$mail->AddAttachment($data->email_attachment[$i], $data->email_attachment_name[$i]);
		}
		
		if (isset($data->emailRemitente) && $data->emailRemitente != "") {
			$mail->From = $data->emailRemitente;
		}
		
		if (isset($data->nombreRemitente) && $data->nombreRemitente != "") {
			$mail->FromName = $data->nombreRemitente;
		}
		
		if (isset($data->email_sender) && $data->email_sender != "") {
			$mail->sender = $data->email_sender;
		}
		
		if (isset($data->asuntoEmail) && $data->asuntoEmail != "") {
			$mail->Subject = $data->asuntoEmail;
		} else {
			$mail->Subject = "";
		}
		
		return $mail->send();
	}